﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;

namespace ProductManager.gui
{
    public partial class GUIReport : DevExpress.XtraEditors.XtraForm
    {

        ProductMDDataContext ctx = null;
        public GUIReport()
        {
            InitializeComponent();
            ctx = new ProductMDDataContext();
        }

        private void GUIReport_Load(object sender, EventArgs e)
        {
            lblTotalCategory.Text = "Total Category: " + ctx.Categories.Count().ToString();
            lblTotalCompany.Text = "Total Company: " + ctx.Companies.Count().ToString();
            lblTotalProduct.Text = "Total Product: " + ctx.Products.Count().ToString();

            var category = ctx.Categories;

            cboCategory.Properties.Items.Clear();
            foreach (Category c in category)
            {
                cboCategory.Properties.Items.Add(c.CategoryName);
            }
            cboCategory.SelectedIndex = 0;
            cboCategory.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
        }

        private void btnAllProduct_Click(object sender, EventArgs e)
        {
            AllProductReport allReport = new AllProductReport();
            allReport.CreateDocument();
            allReport.ShowPreviewDialog();
        }

        private void btnReportByCategory_Click(object sender, EventArgs e)
        {
            int categoryID = ctx.Categories.Single(c => c.CategoryName == cboCategory.SelectedItem).CategoryID;

            ReportByCategory cateReport = new ReportByCategory();
            cateReport.cateID.Value = categoryID;

            cateReport.xrChartQuantity.Series[0].DataFilters[0].Value = categoryID;

            cateReport.CreateDocument();

            cateReport.ShowPreviewDialog();

        }
    }
}